import request from '@/utils/request'
import { GFCD } from '@/utils/utils'

export async function login(data) {
  return request({
    url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
    method: 'post',
    data: {
      data: JSON.stringify(data),
      method: 'sysUserServiceImpl.login',
    },
    notOpenMessage: true,
    baseMessage: true,
  })
}
//验证token是否过期
export async function judgeToken(data = {}) {
  return request({
    url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
    method: 'post',
    data: {
      data: JSON.stringify(data),
      method: 'sysUserServiceImpl.judgeToken',
    },
    notOpenMessage: true,
    baseMessage: true,
  })
}
export async function getSelectResource(data = {}) {
  return request({
    url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
    method: 'post',
    data: {
      data: JSON.stringify(data),
      method: 'sysUserServiceImpl.handleSelectData',
    },
    notOpenMessage: true,
    baseMessage: true,
  })
}
//
export function getUserInfo({ appId, appCode, language = '', datas }) {
  let pdaData = {}
  // 如果是pda模式 添加参数
  if (process.env.VUE_APP_BuildProject === 'pda') {
    pdaData['LOGIN_ENTRANCE'] = 'PDA'
  }
  return request({
    url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
    method: 'post',
    data: {
      data: JSON.stringify({
        ID: appId,
        APP_CODE: appCode,
        LANGUAGE_CODE: language,
        ...datas,
        ...pdaData,
        // token_reset: 'Y',
      }),
      method: 'sysUserServiceImpl.queryResourceByUser',
    },
  })
}
//
export function switchWarehouse(data) {
  return request({
    url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
    method: 'post',
    data: {
      data: JSON.stringify({ TYPE: 'WH_ID', WH_ID: data.WAREHOUSE_ID }),
      method: 'sysUserServiceImpl.modifyConstants',
    },
  })
}

//获取所有语言
export function getLanguges() {
  return request({
    url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
    method: 'post',
    data: {
      data: JSON.stringify({ '#LIMIT#': '1', '#PAGE_SIZE#': '10' }),
      method: 'dams.language.query',
    },
    notOpenMessage: true,
    baseMessage: true,
  })
}

//获取所有组织
// export function getOrgList() {
//   return request({
//     url: GFCD('login', 'domain') + GFCD('login', 'baseUrl'),
//     method: 'post',
//     data: {
//       data: JSON.stringify({ '#LIMIT#': '1', '#PAGE_SIZE#': '10' }),
//       method: 'sysOrganizationServiceImpl.queryTable',
//     },
//   })
// }

//根据组织查询仓库
export function queryByOrgId(orgId = '') {
  return request({
    url: GFCD('dams', 'baseUrl') + this.$store.getters['user/appCodeUrl'],
    method: 'post',
    data: {
      data: JSON.stringify({ ...{ '#LIMIT#': '1', '#PAGE_SIZE#': '10' }, ...{ ORG_ID: orgId } }),
      method: 'wms.warehouse.queryByorgIdAndUserId',
    },
  })
}
